//
//  TripHeaderView.m
//  TravelFollowYourHeart
//
//  Created by ENERGY on 2018/1/20.
//  Copyright © 2018年 Lwx. All rights reserved.
//
#define Border 10
#define labH 50
#define addBtnW 30
#import "TripHeaderView.h"

@interface TripHeaderView()
@property(nonatomic, strong)UIButton * daysBtn;
@property(nonatomic, strong)UIButton * addBtn;
//@property(nonatomic, strong)UIButton
@end

@implementation TripHeaderView

- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithReuseIdentifier:reuseIdentifier];
    if (self) {
        self.contentView.backgroundColor = getColor(bgColor);
        
        [self.contentView addSubview:self.daysBtn];
        [self.contentView addSubview:self.addBtn];
    }return self;
}

- (UIButton *)daysBtn{
    if (!_daysBtn) {
        _daysBtn = [[UIButton alloc] init];
//        [_daysBtn setTitle:@"第一天" forState:UIControlStateNormal];
        _daysBtn.titleLabel.font = DEF_FontSize_18;
        [_daysBtn setCornerRadius:18];
        [_daysBtn setBorderWidth:1 borderColor:[UIColor themeColor]];
//        [_daysBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
        [_daysBtn setTitleColor:[UIColor themeColor] forState:UIControlStateNormal];
//        [_daysBtn addTarget:self action:@selector(daysBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    }return _daysBtn;
}

- (UIButton *)addBtn{
    if (!_addBtn) {
        _addBtn = [[UIButton alloc] init];
        [_addBtn setImage:[UIImage imageNamed:@"WechatIMG25"] forState:UIControlStateNormal];
        [_addBtn addTarget:self action:@selector(addTripBtnClick) forControlEvents:UIControlEventTouchUpInside];
    }return _addBtn;
}

- (void)layoutSubviews{
    [super layoutSubviews];
    self.daysBtn.frame = CGRectMake(Border, 0, 100, self.contentView.height);
    self.addBtn.frame = CGRectMake(SCREEN_WIDTH - addBtnW - Border, 0, addBtnW, self.contentView.height);
}

- (void)addTripBtnClick{
    if ([self.delegate respondsToSelector:@selector(addTheDayTrip:)]) {
        [self.delegate addTheDayTrip:self.daysBtn.titleLabel.text];
    }
}

- (void)setHeadModel:(NSDictionary *)headModel{
    _headModel = headModel;
    [self.daysBtn setTitle:[headModel objectForKey:@"days"] forState:UIControlStateNormal];
}

//- (void)daysBtnClick:(UIButton *)sender{
//    sender.selected = !sender.selected;
//    if (sender.selected) {
//        [sender setBackgroundColor:[UIColor themeColor]];
//    }else{
//        [sender setBackgroundColor:[UIColor whiteColor]];
//
//    }
//}

@end
